~4Dgifts/toolbox/src/exampleCode/GLX/littleRedCap README littleRedCap: An interference checking and capping demo Capping is a trick employed so that we can use hollow models to portray solids, and is used in applications where objects could be clipped (such as CAD). Interference checking is a method of showing the regions of intersection between two separate objects. This mixed model example is based on Kurt Akeley's 'cap' program. It is by no means as robust in a demonstrational sense, meaning it does not read object in from a file, nor can one move around the clipping planes or the viewpoint. What it does do is to apply a clipping plane in the XY plane at z=0, and bring up two torii. The clipped torii are capped using the same material as the rest of each respective surface. The interference between the two objects is shown in red. The yellow square is an outline of a plane coinciding to the arbitrary clipping plane 0. The axes are drawn at the origin to indicate the orientation of the clipping plane. The capping and interference checking are both done using the stencil buffer. In order for the program to run, your graphics needs to support stenciling. If it doesn't the program will tell you so and then bail. The good news is that Open GL requires the presence of at least one stencil plane, so this restriction will not exist when you migrate to it. The capping is done by rendering each object in the scene twice. The first time, the objects are each drawn with backfacing on (since the capping will prevent the user from seeing the inner portions of the clipped objects). Then we disable writes to the color and depth buffers. We'll use the low order bit of the stencil buffer to determine where we've drawn part of the object. Then we'll draw the object again, using the stencil buffer to keep track of which pixels we've tried to draw something to. Where the value in the stencil buffer is odd, the inside of the solid was (rather would have been) visible. After the object is rendered for the second time, we draw the clipping plane, using the same material property as the object's. In order to make sure that the cap is drawn correctly, we do two things. First, we shut off the clipping plane (otherwise the cap itself could be clipped). Then, we transform the origin to the location of the clipping plane. This prevents any problems related to viewer position from occuring. For example, if the origin of the model view matrix were not where we expected, the cap might be drawn at an offset to its expected position. The interference checking is done after all of the objects in the scene are drawn with their caps. Since the values in the stencil buffer are still intact, we draw a large rectangle stenciling those regions with pixel access counts of two or greater. In this example, we draw a red rectangle, ergo the name "little red cap". Objects can be animated to ensure the capping and interference checking is done in real time. To change the objects, their properties, or transforms, edit the shapes data structure in gl_interfere.c. Refer to shapes.h for all available shapes. This data structure will also take a uniform scaling factor if you wish to grow or shrink each shape. There is a known bug at startup where some or all of the inner window is painted red until one moves the window or presses the Animate button. Paul C. David pcd@sgi.com 9/93
Source
Documentation
Reference